﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using Jumbot.Common;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Ajax
{
    public partial class _user : JumbotCms.API.FrontAjax
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!CheckFormUrl())
            {
                Response.Write("提交有误");
                Response.End();
            }
            Server.ScriptTimeout = 8;//脚本过期时间
            this._operType = q("oper");
            switch (this._operType)
            {
                case "ajaxLoginbar":
                    GetLoginbar();
                    break;
                case "ajaxUserInfo":
                    GetUserInfo();
                    break;
                default:
                    DefaultResponse();
                    break;
            }

            Response.Write(this._response);
        }

        private void DefaultResponse()
        {
            this._response = "{result :\"未知操作\"}";
        }
        private void GetUserInfo()
        {
            string tempBody = string.Empty;
            string _userid = "0";
            string _groupname = string.Empty;
            if (Cookie.GetValue(site.CookiePrev + "user") != null)
            {
                _userid = Cookie.GetValue(site.CookiePrev + "user", "id");
                _groupname = Cookie.GetValue(site.CookiePrev + "user", "groupname");
                tempBody = "{result :\"1\",";
                JumbotCms.DataObject.User _User = new JumbotCms.DataObject.User();
                _User.GetAllColumn(_userid, doh);
                tempBody += "userid :\"" + _User.Id + "\"," +
                    "username :\"" + _User.UserName + "\"," +
                    "userpass :\"" + _User.UserPass + "\"," +
                    "userkey :\"" + _User.UserPass.Substring(4, 8) + "\"," +
                    "email :\"" + _User.Email + "\"," +
                    "sex :\"" + _User.Sex + "\"," +
                    "iswriter :\"" + _User.IsWriter + "\"," +
                    "isvip :\"" + _User.IsVIP + "\"," +
                    "vipdate :\"" + _User.VIPDate + "\"," +
                    "truename :\"" + _User.TrueName + "\"," +
                    "idtype :\"" + _User.IDType + "\"," +
                    "idcard :\"" + _User.IDCard + "\"," +
                    "points :\"" + _User.Points + "\"," +
                    "integral :\"" + _User.Integral + "\"," +
                    "groupname :\"" + _groupname + "\"," +
                    "birthday :\"" + _User.BirthDay + "\"," +
                    "comefrom :\"" + _User.ComeFrom + "\"," +
                    "workunit :\"" + _User.WorkUnit + "\"," +
                    "address :\"" + _User.Address + "\"," +
                    "zipcode :\"" + _User.ZipCode + "\"," +
                    "qq :\"" + _User.QQ + "\"," +
                    "msn :\"" + _User.MSN + "\"," +
                    "languages :\"" + _User.Languages + "\"," +
                    "graduatefrom :\"" + _User.GraduateFrom + "\"," +
                    "studyway :\"" + _User.StudyWay + "\"," +
                    "mobiletel :\"" + _User.MobileTel + "\"," +
                    "telephone :\"" + _User.Telephone + "\"," +
                    "cardusername :\"" + _User.CardUserName + "\"," +
                    "cardbank :\"" + _User.CardBank + "\"," +
                    "cardnumber :\"" + _User.CardNumber + "\"," +
                    "homepage :\"" + _User.HomePage + "\"," +
                    "adminid :\"" + _User.AdminId + "\"," +
                    "adminname :\"" + _User.AdminName + "\"" +
                    "}";
            }
            else
            {
                tempBody = "{result :\"0\",";
                tempBody += "userid :\"0\"," +
                    "username :\"\"," +
                    "userpass :\"\"," +
                    "userkey :\"\"," +
                    "email :\"\"," +
                    "sex :\"0\"," +
                    "iswriter :\"0\"," +
                    "isvip :\"0\"," +
                    "vipdate :\"\"," +
                    "truename :\"\"," +
                    "idtype :\"\"," +
                    "idcard :\"\"," +
                    "points :\"\"," +
                    "integral :\"\"," +
                    "groupname :\"\"," +
                    "birthday :\"\"," +
                    "comefrom :\"\"," +
                    "workunit :\"\"," +
                    "address :\"\"," +
                    "zipcode :\"\"," +
                    "qq :\"\"," +
                    "msn :\"\"," +
                    "languages :\"\"," +
                    "graduatefrom :\"\"," +
                    "studyway :\"\"," +
                    "mobiletel :\"\"," +
                    "telephone :\"\"," +
                    "cardusername :\"\"," +
                    "cardbank :\"\"," +
                    "cardnumber :\"\"," +
                    "homepage :\"\"," +
                    "adminid :\"0\"," +
                    "adminname :\"\"" +
                    "}";
            }
            this._response = tempBody;
        }
        private void GetLoginbar()
        {
            string tempBody = string.Empty;
            string returninfo = string.Empty;
            if (f("state") == "1")
            {
                string uName = f("name");
                string uPass = f("pass");
                returninfo = ChkUserLogin(uName, uPass, 1);
            }
            if (Cookie.GetValue(site.CookiePrev + "user") != null)
            {
                string UserId = Cookie.GetValue(site.CookiePrev + "user", "id");
                string UserName = Cookie.GetValue(site.CookiePrev + "user", "name");
                string UserPass = Cookie.GetValue(site.CookiePrev + "user", "password");
                string UserGroupName = Cookie.GetValue(site.CookiePrev + "user", "groupname");
                JumbotCms.DataObject.User _User = new JumbotCms.DataObject.User();
                _User.GetAllColumn(UserId, doh);
                tempBody = "{result :\"1\"," +
                    "userid :\"" + UserId + "\"," +
                    "username :\"" + UserName + "\"," +
                    "userpass :\"" + UserPass + "\"," +
                    "userkey :\"" + UserPass.Substring(4, 8) + "\"," +
                    "points :\"" + _User.Points + "\"," +
                    "integral :\"" + _User.Integral + "\"," +
                    "isvip :\"" + _User.IsVIP + "\"," +
                    "vipdate :\"" + _User.VIPDate + "\"," +
                    "groupname :\"" + UserGroupName + "\"," +
                    "adminid :\"" + _User.AdminId + "\"" +
                    "}";
                this._response = tempBody;
            }
            else
            {
                this._response = "{result :\"0\"";
                if (f("state") == "1")
                    this._response += ",returnval :\"" + returninfo + "\"";
                this._response += "}";
            }
        }
    }
}